<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span v-if="edit">更新设备</span>
            <span v-else>新增设备</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-input v-model="data.id" type="hidden" />
            <el-row :gutter="10">
              <el-col :span="4">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="brand">
                  <div>品牌</div>
                  <el-input v-model="data.brand" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="spec">
                  <div>型号</div>
                  <el-input v-model="data.spec" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="cost_id">
                  <div>成本中心</div>
                  <v-select v-model="data.cost_id" action="costList" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="weight">
                  <div>类别</div>
                  <el-select v-model="data.weight" placeholder="请选择" size="mini">
                    <el-option v-for="(item, weightIndex) in weight" :key="weightIndex" :label="item" :value="weightIndex" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="fun">
                  <div>资产性质</div>
                  <el-select v-model="data.fun" placeholder="请选择" size="mini">
                    <el-option v-for="(item, funIndex) in fun" :key="funIndex" :label="item" :value="funIndex" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="status">
                  <div>状态</div>
                  <el-select v-model="data.status" placeholder="请选择" size="mini">
                    <el-option v-for="(item, statusIndex) in eqStatus" :key="statusIndex" :label="item" :value="statusIndex" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="provider_id">
                  <div>供应商</div>
                  <v-select-s v-model="data.provider_id" action="onlyProviderList" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="manufacturer_id">
                  <div>制造商</div>
                  <v-select-s v-model="data.manufacturer_id" action="onlyManufacturerList" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="serialize">
                  <div>出厂编号</div>
                  <el-input v-model="data.serialize" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="workshop">
                  <div>所属车间</div>
                  <v-select v-model="data.workshop" action="workshopList" :query="{factory_id:data.factory}" @change="clearLine" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="line">
                  <div>所属生产线</div>
                  <v-select v-model="data.line" action="lineList" :query="{workshop_id:data.workshop}" @change="clearProcess" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="process">
                  <div>所属工位</div>
                  <v-select v-model="data.process" action="processList" :query="{line_id:data.line}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="parent_id">
                  <div>第一级资产</div>
                  <v-select v-model="data.parent_id" :disabled="!data.process" :query="{position_id:data.process}" action="eqList" :is-top="true" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="position">
                  <div>存放位置</div>
                  <el-input v-model="data.position" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="4" :md="6" :sm="8" hidden>
                <el-form-item prop="org">
                  <div>组织</div>
                  <v-select v-model="data.org" action="orgList" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="4" :md="6" :sm="8" hidden>
                <el-form-item prop="department">
                  <div>部门</div>
                  <v-select v-model="data.department" :disabled="!data.org" :query="{org:data.org}" action="departmentList" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="first_category">
                  <div>一级分类</div>
                  <v-select v-model="data.first_category" action="eqCategoryList" :query="{level:0}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="category_id">
                  <div>终极分类</div>
                  <v-select v-model="data.category_id" action="eqCategoryList" :disabled="!data.first_category" :query="{parent_id:data.first_category}" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="hb">
                  <div>环保设备</div>
                  <el-checkbox v-model="data.hb" true-label="1" false-label="0">环保设备</el-checkbox>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="special">
                  <div>特种设备</div>
                  <el-checkbox v-model="data.special" true-label="1" false-label="0">特种设备</el-checkbox>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="purchase_date">
                  <div>生产日期</div>
                  <el-date-picker v-model="data.purchase_date" type="date" size="mini" value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="manufacture_date">
                  <div>购置日期</div>
                  <el-date-picker v-model="data.manufacture_date" type="date" size="mini" value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="price">
                  <div>购置价格</div>
                  <el-input v-model="data.price" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="used_group">
                  <div>使用岗位</div>
                  <v-select-s v-model="data.used_group" action="jobList" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="admin_id">
                  <div>保全班长</div>
                  <v-select-s v-model="data.admin_id" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="monitor_id">
                  <div>车间班组长</div>
                  <v-select-s v-model="data.monitor_id" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="motor">
                  <div>电机数</div>
                  <el-input v-model="data.motor" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="power">
                  <div>功率</div>
                  <el-input v-model="data.power" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs v-if="edit">
            <el-tab-pane label="描述">
              <el-row :gutter="10">
                <el-col :span="4">
                  <div>
                    <span>创建时间日期</span>
                    <el-input v-model="data.create_time" placeholder="创建时间日期" class="mtb10" size="mini" :disabled="true" />
                  </div>
                  <div>
                    <span>创建人</span>
                    <el-input v-model="data.cr_admin.name" placeholder="创建人" class="mtb10" size="mini" :disabled="true" />
                  </div>
                  <div v-if="data.update_time">
                    <div>
                      <span>最近更新</span>
                      <el-input v-model="data.update_time" placeholder="最近更新" class="mtb10" size="mini" :disabled="true" />
                    </div>
                    <div>
                      <span>更新者</span>
                      <el-input v-model="data.up_admin.name" placeholder="更新者" class="mtb10" size="mini" :disabled="true" />
                    </div>
                  </div>
                </el-col>
                <el-col :span="16">
                  <Tinymce id="content" :v-model="content" :height="1000" />
                </el-col>
                <el-col :span="4">
                  <thumb v-model="data.thumb" />
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane lazy label="维护负责人">
              <el-collapse v-model="planAdmin" accordion>
                <el-collapse-item title="自主点检（操作者）" name="1">
                  <el-table :data="data.zzdjList">
                    <el-table-column min-width="80%" label="姓名" prop="name" />
                    <el-table-column min-width="20%" label="操作" align="center">
                      <template slot-scope="{row}">
                        <el-button type="danger" size="mini" @click="planAdminDel(row.id)">删除</el-button>
                      </template>
                    </el-table-column>
                    <div slot="append" style="margin: 20px 0; overflow: hidden;">
                      <el-col :span="20">
                        <v-select-s v-model="planAdmins.adminId" action="adminList" />
                      </el-col>
                      <el-col :span="4" align="center">
                        <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="planAdminSave(0)" />
                      </el-col>
                    </div>
                  </el-table>
                </el-collapse-item>
                <el-collapse-item title="专业点检" name="2">
                  <el-table :data="data.zydjList">
                    <el-table-column min-width="80%" label="姓名" prop="name" />
                    <el-table-column min-width="20%" label="操作" align="center">
                      <template slot-scope="{row}">
                        <el-button type="danger" size="mini" @click="planAdminDel(row.id)">删除</el-button>
                      </template>
                    </el-table-column>
                    <div slot="append" style="margin: 20px 0; overflow: hidden;">
                      <el-col :span="20">
                        <v-select-s v-model="planAdmins.adminId" action="adminList" />
                      </el-col>
                      <el-col :span="4" align="center">
                        <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="planAdminSave(4)" />
                      </el-col>
                    </div>
                  </el-table>
                </el-collapse-item>
                <el-collapse-item title="自主维护" name="3">
                  <el-table :data="data.zzwhList">
                    <el-table-column min-width="80%" label="姓名" prop="name" />
                    <el-table-column min-width="20%" label="操作" align="center">
                      <template slot-scope="{row}">
                        <el-button type="danger" size="mini" @click="planAdminDel(row.id)">删除</el-button>
                      </template>
                    </el-table-column>
                    <div slot="append" style="margin: 20px 0; overflow: hidden;">
                      <el-col :span="20">
                        <v-select-s v-model="planAdmins.adminId" action="adminList" />
                      </el-col>
                      <el-col :span="4" align="center">
                        <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="planAdminSave(1)" />
                      </el-col>
                    </div>
                  </el-table>
                </el-collapse-item>
                <el-collapse-item title="专业维护" name="4">
                  <el-table :data="data.zywhList">
                    <el-table-column min-width="80%" label="姓名" prop="name" />
                    <el-table-column min-width="20%" label="操作" align="center">
                      <template slot-scope="{row}">
                        <el-button type="danger" size="mini" @click="planAdminDel(row.id)">删除</el-button>
                      </template>
                    </el-table-column>
                    <div slot="append" style="margin: 20px 0; overflow: hidden;">
                      <el-col :span="20">
                        <v-select-s v-model="planAdmins.adminId" action="adminList" />
                      </el-col>
                      <el-col :span="4" align="center">
                        <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="planAdminSave(2)" />
                      </el-col>
                    </div>
                  </el-table>
                </el-collapse-item>
                <el-collapse-item title="润滑" name="5">
                  <el-table :data="data.rhList">
                    <el-table-column min-width="80%" label="姓名" prop="name" />
                    <el-table-column min-width="20%" label="操作" align="center">
                      <template slot-scope="{row}">
                        <el-button type="danger" size="mini" @click="planAdminDel(row.id)">删除</el-button>
                      </template>
                    </el-table-column>
                    <div slot="append" style="margin: 20px 0; overflow: hidden;">
                      <el-col :span="20">
                        <v-select-s v-model="planAdmins.adminId" action="adminList" />
                      </el-col>
                      <el-col :span="4" align="center">
                        <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="planAdminSave(3)" />
                      </el-col>
                    </div>
                  </el-table>
                </el-collapse-item>
              </el-collapse>
            </el-tab-pane>
            <el-tab-pane lazy label="负责工程师">
              <el-table :data="data.engineerList">
                <el-table-column min-width="80%" label="姓名" prop="name" />
                <el-table-column min-width="20%" label="操作" align="center">
                  <template slot-scope="{row}">
                    <el-button type="danger" size="mini" @click="removeEngineer(row.id)">删除</el-button>
                  </template>
                </el-table-column>
                <div slot="append" style="margin: 20px 0; overflow: hidden;">
                  <el-col :span="20">
                    <v-select-s v-model="engineerAdmins.adminId" action="adminList" />
                  </el-col>
                  <el-col :span="4" align="center">
                    <el-button icon="el-icon-upload2" size="mini" style="margin: 0 auto;" @click="appendEngineer" />
                  </el-col>
                </div>
              </el-table>
            </el-tab-pane>
            <el-tab-pane lazy label="关联知识">
              <el-collapse v-model="knowledgeCategoryActive" accordion>
                <el-collapse-item v-for="(item, wrapIndex) in knowledge_list" :key="wrapIndex" :title="item.name" :name="wrapIndex+1">
                  <ul v-for="(i, kIndex) in item.list" :key="kIndex" :title="i.name" :name="kIndex+1">
                    <li v-for="(is, sIndex) in i.knowledges" :key="sIndex" style="list-style: none;">
                      <a v-if="is.base_url === 1" :href="host+is.path" target="_blank"><p>{{ is.name.split('/')[is.name.split('/').length-1] }}</p></a>
                      <a v-if="is.base_url === 2" :href="is.path" target="_blank"><p>{{ is.name.split('/')[is.name.split('/').length-1] }}</p></a>
                    </li>
                  </ul>
                </el-collapse-item>
              </el-collapse>
            </el-tab-pane>
            <el-tab-pane lazy label="维修负责人">
              <el-table :data="admin_list">
                <el-table-column label="姓名" min-width="24%" prop="admin.name">
                  <template slot-scope="{row}">
                    <span v-if="row.admin">{{ row.admin.name }}</span>
                    <span v-else>已删除</span>
                  </template>
                </el-table-column>
                <el-table-column label="电话" min-width="24%" prop="admin.phone">
                  <template slot-scope="{row}">
                    <span v-if="row.admin">{{ row.admin.phone }}</span>
                    <span v-else>已删除</span>
                  </template>
                </el-table-column>
                <el-table-column label="岗位" min-width="24%" prop="admin.admin_jobs.name" />
                <el-table-column label="状态" min-width="16%" prop="admin.status">
                  <template slot-scope="{row}">
                    <span v-if="row.admin">{{ theStatus[row.admin.status] }}</span>
                    <span v-else>已删除</span>
                  </template>
                </el-table-column>
                <el-table-column label="操作" min-width="8%">
                  <template scope="scope">
                    <el-button type="text" size="small" @click="adminIdsDel(scope.row.id)">删除</el-button>
                  </template>
                </el-table-column>
                <div slot="append">
                  <el-form ref="eq_admins_form" :model="admins" :inline="true" class="hf_form append_other_admin" :rules="adminsRules">
                    <el-row :gutter="10">
                      <el-col :span="6">
                        <el-form-item prop="admin_id">
                          <v-select-s v-model="admins.admin_id" action="adminList" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="6">
                        <el-form-item>
                          <el-input disabled size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="6">
                        <el-form-item>
                          <el-input disabled size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="4">
                        <el-form-item>
                          <el-input disabled size="mini" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="2">
                        <el-form-item>
                          <el-button icon="el-icon-upload2" size="mini" @click="adminsSave" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                </div>
              </el-table>
            </el-tab-pane>
            <el-tab-pane lazy label="关联备件">
              <template>
                <el-table :data="parts_list" :stripe="true">
                  <el-table-column min-width="15%" label="备件" prop="parts.name" />
                  <el-table-column min-width="65%" label="注意" prop="notice" />
                  <el-table-column min-width="20%" label="品牌" prop="parts.brand" />
                </el-table>
              </template>
            </el-tab-pane>
            <el-tab-pane lazy label="维修备件">
              <template>
                <div class="part">
                  <el-table :data="cm_parts_list">
                    <el-table-column label="日期" prop="create_time" />
                    <el-table-column label="工单" prop="wordorder">
                      <template slot-scope="{row}">{{ row.coding }} - {{ row.name }}</template>
                    </el-table-column>
                    <el-table-column label="备品备件">
                      <template slot-scope="{row}">
                        <div v-for="(item, partsIndex) in row.used_parts_list" :key="partsIndex">
                          <p>{{ item.parts.name }}</p>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column label="出库数量">
                      <template slot-scope="{row}">
                        <div v-for="(item, numberIndex) in row.used_parts_list" :key="numberIndex">
                          <p>{{ item.number }}{{ item.parts.unit }}</p>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column label="单价 (¥)">
                      <template slot-scope="{row}">
                        <div v-for="(item, priceIndex) in row.used_parts_list" :key="priceIndex">
                          <p>{{ item.parts.price }}元</p>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column label="总价 (¥)" prop="total_price">
                      <template slot-scope="{row}">
                        <div v-for="(item, totalPriceIndex) in row.used_parts_list" :key="totalPriceIndex">
                          <p>{{ item.parts.price * item.number }}元</p>
                        </div>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </template>
            </el-tab-pane>
            <el-tab-pane lazy label="维护计划">
              <el-table :data="plan_list">
                <el-table-column label="编码" prop="coding" />
                <el-table-column label="名称" prop="name" />
                <el-table-column label="优先程度" prop="priority">
                  <template v-slot="{row}">{{ priority[row.priority] }}</template>
                </el-table-column>
                <el-table-column label="类别">
                  <template v-slot="{row}">{{ planCategory[row.plan_category] }}</template>
                </el-table-column>
                <el-table-column label="专业" prop="profession">
                  <template v-slot="{row}">{{ profession[row.profession] }}</template>
                </el-table-column>
                <el-table-column label="安排时间" prop="arrange_date" />
              </el-table>
            </el-tab-pane>
            <el-tab-pane lazy label="故障树">
              <template>
                <el-table :data="failure_list">
                  <el-table-column label="部位" prop="parts" />
                  <el-table-column label="次数" prop="times" />
                </el-table>
              </template>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import API from '@/api/asset/equipment'
import { weight, fun, eqStatus, priority, planCategory, profession, theStatus } from '@/utils/options'
import Tinymce from '@/components/Tinymce'
import thumb from '@/components/Upload/thumb'
import components from '@/components/asset/equipment/index'
import VSelect from '@/components/select'
import VSelectS from '@/components/select-search'
export default {
  inject: ['backUrl', 'delOne', 'update', 'addOne', 'appendOtherAdmin', 'delOtherAdmin', 'getWeightFormat', 'goUrl', 'isEdit'],
  components: {
    Tinymce,
    thumb,
    VSelect,
    VSelectS,
    ...components
  },
  data() {
    return {
      host: 'http://beiqi.aiemtc.com',
      active: 1,
      activeName: 1,
      knowledgeActive: 0,
      planAdmin: 1,
      knowledgeCategoryActive: 0,
      data: {
        admin: {
          phone: ''
        },
        cr_admin: {
          name: ''
        },
        line: null,
        process: null
      },
      content: '<p>33333</p>',
      parts_list: [],
      cm_parts_list: [],
      plan_list: [],
      failure_list: [],
      admin_list: [],
      knowledge_list: [],
      admins: {},
      weight,
      fun,
      eqStatus,
      priority,
      planCategory,
      profession,
      theStatus,
      formRules: {
        name: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ],
        brand: [
          {
            required: true,
            message: '请输入品牌',
            trigger: 'blur'
          }
        ],
        spec: [
          {
            required: true,
            message: '请输入型号 ',
            trigger: 'blur'
          }
        ],
        cost_id: [
          {
            required: true,
            message: '请选择成本中心',
            trigger: 'change'
          }
        ],
        weight: [
          {
            required: true,
            message: '请选择类别',
            trigger: 'change'
          }
        ],
        fun: [
          {
            required: true,
            message: '请选择功能',
            trigger: 'change'
          }
        ],
        status: [
          {
            required: true,
            message: '请选择状态',
            trigger: 'change'
          }
        ],
        first_category: [
          {
            required: true,
            message: '请选择一级分类',
            trigger: 'change'
          }
        ],
        category_id: [
          {
            required: true,
            message: '请选择终极分类',
            trigger: 'change'
          }
        ],
        factory: [
          {
            required: true,
            message: '请选择所属工厂',
            trigger: 'change'
          }
        ],
        workshop: [
          {
            required: true,
            message: '请选择所属车间',
            trigger: 'change'
          }
        ],
        line: [
          {
            required: true,
            message: '请选择所属生产线',
            trigger: 'change'
          }
        ],
        process: [
          {
            required: true,
            message: '请输入所属工位',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ],
        used_group: [
          {
            required: true,
            message: '请选择使用岗位',
            trigger: 'change'
          }
        ]
      },
      adminsRules: {
        admin_id: [
          {
            required: true,
            message: '请选择负责人',
            trigger: 'change'
          }
        ]
      },
      edit: false,
      planAdmins: {
        adminId: null
      },
      engineerAdmins: {
        adminId: null
      }
    }
  },
  watch: {
  },
  created() {
    this.index()
  },
  methods: {
    index() {
      if (this.isEdit()) {
        this.edit = true
        this.info()
      }
    },
    info() {
      const id = this.$route.params.id
      API.getOne(id).then(response => {
        if (response.data.error_code === 24404) {
          this.$alert('您请求的设备不存在', '错误', {
            confirmButtonText: '确定',
            callback: () => {
              this.backUrl()
            }
          })
        }
        if (response.data.failure_list.length !== 0) {
          const failList = []
          for (const key in response.data.failure_list) {
            const temp = {}
            temp.parts = key
            temp.times = response.data.failure_list[key]
            failList.push(temp)
          }
          this.failure_list = failList
        }
        this.data = response.data
        this.parts_list = response.data.part
        this.cm_parts_list = response.data.used_parts_list
        this.plan_list = response.data.pm_list
        this.admin_list = response.data.admin_list
        this.knowledge_list = response.data.knowledge_list
        if (this.data.hb === 0) {
          this.data.hb = false
        } else if (this.data.hb === 1) {
          this.data.hb = true
        }

        if (this.data.special === 0) {
          this.data.special = false
        } else if (this.data.special === 1) {
          this.data.special = true
        }
        // this.content = response.data.content
        console.log(this.content)
      })
    },
    inspect(value) {
      this.$set(this.data, 'inspect', value)
    },
    confirmDel() {
      const id = this.data.id
      this.delOne(API, id, true)
    },
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.edit ? this.update(API, thisData, thisForm) : this.addOne(API, thisData, thisForm)
    },
    append() {
      const thisForm = this.$refs.append_form
      const admin_data = {
        'admin_id': this.data.admin_id,
        'category': this.$route.params.id,
        'weight': this.data.weight
      }
      const errorCode = 92004
      const errorMessage = '该人员已存在'
      this.appendOtherAdmin(API, thisForm, admin_data, errorCode, errorMessage)
    },
    otherAdminDel(admin_id) {
      const admin_data = {
        'admin_id': admin_id,
        'category': this.$route.params.id
      }
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        API.delOtherAdmin(admin_data).then((response) => {
          if (response.data.error_code === 1) {
            this.$message({
              message: '恭喜你，删除成功',
              type: 'success'
            })
            API.category(this.$route.params.id).then(response => {
              this.list = response.data.other_admin
            })
          } else {
            this.$message.error(response.data.message)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    weightFormat(row) {
      return this.getWeightFormat(row)
    },
    clearLine() {
      this.data.line = null
      this.data.process = null
    },
    clearProcess() {
      this.data.process = null
    },
    adminIdsDel(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        API.remove({ 'id': id }).then((response) => {
          if (response.data.error_code === 1) {
            this.$message({
              message: '恭喜你，删除成功',
              type: 'success'
            })
            API.getOne(this.$route.params.id).then(response => {
              this.admin_list = response.data.admin_list
            })
          } else {
            this.$message.error(response.data.message)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    adminsSave() {
      this.$refs.eq_admins_form.validate((valid) => {
        if (valid) {
          const admin_data = {
            'admin_id': this.admins.admin_id,
            'equipment_id': this.$route.params.id
          }
          API.append(admin_data).then(response => {
            if (response.data.error_code === 1) {
              this.$message({
                message: '恭喜你，更新成功',
                type: 'success'
              })
              API.getOne(this.$route.params.id).then(response => {
                this.admin_list = response.data.admin_list
              })
            } else {
              this.$message.error(response.data.message)
            }
          })
        }
      })
    },
    goBack() {
      this.goUrl('/asset/equipment')
    },
    planAdminSave(plan_category) {
      const data = {
        equipment_id: this.data.id,
        admin_id: this.planAdmins.adminId,
        plan_category
      }
      API.appendPlanAdmin(data).then(res => {
        if (res.data.error_code === 1) {
          this.$message({
            message: '恭喜你，添加成功',
            type: 'success'
          })
          this.info()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    planAdminDel(id) {
      API.removePlanAdmin({ id }).then(res => {
        if (res.data.error_code === 1) {
          this.$message({
            message: '恭喜你，删除成功',
            type: 'success'
          })
          this.info()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    appendEngineer() {
      const data = {
        equipment_id: this.data.id,
        admin_id: this.planAdmins.adminId
      }
      API.appendEngineer(data).then(res => {
        if (res.data.error_code === 1) {
          this.$message({
            message: '恭喜你，添加成功',
            type: 'success'
          })
          this.info()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    removeEngineer(id) {
      API.removeEngineer({ id }).then(res => {
        if (res.data.error_code === 1) {
          this.$message({
            message: '恭喜你，删除成功',
            type: 'success'
          })
          this.info()
        } else {
          this.$message.error(res.data.message)
        }
      })
    }
  }
}
</script>
<style>
.mtb10{
  margin: 10px 0;
}
</style>
